<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>收益统计</title>
  <script type="text/javascript" src="./js/layui.all.js"></script>
  <script type="text/javascript" src="./js/jquery.min.js"></script>
  <link rel="stylesheet" href="./css/layui.css" media="all">
  <link rel="stylesheet" href="./css/layer.css" media="all">
  <link rel="stylesheet" href="./css/laydate.css" media="all">
  <style>
    body{margin: 30px;}
    .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
  </style>
</head>
<body>
 
  <div class="layui-form-item" style="width:100%">
    <div class="layui-row">
      <div class="layui-inline">
        <label class="layui-form-label">脚本账号</label>
        <div class="layui-input-inline">
          <input type="tel" id="username" name="username" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">脚本密码</label>
        <div class="layui-input-inline">
          <input type="text" id="password" name="password" autocomplete="off" class="layui-input">
        </div>
      </div>
      <p class="layui-inline" style="font-size: 15px;color: red;">注：多个脚本账号，只需要填写其中一个，即可查询相关联的QQ下面的所有收益统计数据</p>
    </div>
    
    <div class="layui-inline">
      <label class="layui-form-label">金币&gt;=</label>
      <div class="layui-input-inline">
        <input type="text" id="goldMin" name="goldMin" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">金币&lt;=</label>
      <div class="layui-input-inline">
        <input type="text" id="goldMax" name="goldMax" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">银币&gt;=</label>
      <div class="layui-input-inline">
        <input type="text" id="silverMin" name="silverMin" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">银币&lt;=</label>
      <div class="layui-input-inline">
        <input type="text" id="silverMax" name="silverMax" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">服务器</label>
      <div class="layui-input-inline">
        <input type="text" id="serverName" name="serverName" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">角色名</label>
      <div class="layui-input-inline">
        <input type="text" id="roleName" name="roleName" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">记录日期</label>
      <div class="layui-input-inline">
        <input type="text" name="recordDateMin" id="recordDateMin" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-mid">-</div>
      <div class="layui-input-inline">
        <input type="text" name="recordDateMax" id="recordDateMax" lay-verify="date" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <button id="do_search" type="button" class="layui-btn layui-btn-normal layui-btn-radius">查询</button>
    </div>
  </div>

  <div class="layui-form-item" style="width:100%">
    <div class="layui-row">
      <button id="delBatch" type="button" class="layui-btn layui-btn-radius layui-btn-danger">批量删除</button>
    </div>
  </div>
  
<table class="layui-hide" id="dataTableId" lay-filter="dataTable" lay-data="{id: 'idTest'}" ></table>
 
<script type="text/html" id="barDemo">
  <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>
 

<script>

Array.prototype.remove = function () {
    for (var i = 0; i < arguments.length; i++) {
        var ele = arguments[i];
        var index = this.indexOf(ele);
        if (index > -1) {
            this.splice(index, 1);
        }
    }
};
 
layui.use(['laydate', 'laypage', 'layer', 'table'], function(){
  var laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  

  //日期
  laydate.render({
    elem: '#recordDateMin'
    ,type: 'datetime'
  });
  laydate.render({
    elem: '#recordDateMax'
    ,type: 'datetime'
  });

  
  //执行一个 table 实例
  table.render({
    elem: '#dataTableId'
    ,height: 'full-205'
    ,title: '收益统计表'
    ,page: true //开启分页
    ,toolbar: true  //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
    ,totalRow: true //开启合计行
    ,cols: [[ //表头
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'uid', title: 'ID', sort: true, fixed: 'left', totalRowText: '合计：'}
      ,{field: 'serverName', title: '服务器'}
      ,{field: 'roleName', title: '角色名'}
      ,{field: 'gold', title: '金币', sort: true, totalRow: true}
      ,{field: 'silver', title: '银币', sort: true, totalRow: true}
      ,{field: 'equipment', title: '设备标识', sort: true} 
      ,{field: 'yxUsername', title: '游戏账号'}
      ,{field: 'yxPassword', title: '游戏密码'}
      ,{field: 'updateDate', title: '记录时间', sort: true,  templet:'<div>{{ layui.util.toDateString(d.updateDate, "yyyy-MM-dd HH:mm:ss") }}</div>'}
      ,{fixed: 'right', align:'center', toolbar: '#barDemo'}
    ]],
    data:[]
  });
  
  //监听头工具栏事件
  table.on('toolbar(dataTable)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id)
    ,data = checkStatus.data; //获取选中的数据
    switch(obj.event){
      case 'add':
        layer.msg('添加');
      break;
      case 'update':
        if(data.length === 0){
          layer.msg('请选择一行');
        } else if(data.length > 1){
          layer.msg('只能同时编辑一个');
        } else {
          layer.alert('编辑 [id]：'+ checkStatus.data[0].id);
        }
      break;
      case 'delete':
        if(data.length === 0){
          layer.msg('请选择一行');
        } else {
          layer.msg('删除');
        }
      break;
    };
  });

  
  $('#do_search').on('click', function () {
    var username = $("#username").val();
    var password = $("#password").val();
    var goldMin = $("#goldMin").val();
    var goldMax = $("#goldMax").val();
    var silverMin = $("#silverMin").val();
    var silverMax = $("#silverMax").val();
    var serverName = $("#serverName").val();
    var roleName = $("#roleName").val();
    var startTime = $("#recordDateMin").val();
    var endTime = new Date($("#recordDateMax").val()).getTime();
    startTime = startTime.length > 0 ? new Date(startTime).getTime() : '';
    endTime = endTime.length > 0 ? new Date(endTime).getTime() : '';

    table.reload('dataTableId', {
      url: 'http://xiaoc.store/verify/yxmh/getList',
      method: "post",
      where: {
        username: username,
        password: password,
        goldMin: goldMin,
        goldMax: goldMax,
        silverMin: silverMin,
        silverMax: silverMax,
        serverName: serverName,
        roleName: roleName,
        softId:'1198141497808330753',
        startTime: startTime,
        endTime: endTime
      },
      response:{
        statusName: 'code'
        ,statusCode: 9
        ,msgName: 'msg'
        ,countName: 'count'
        ,dataName: 'data'
      }
    });
  });
  
  $("#delBatch").on("click",function(){
    var delUids = [];
    var checkStatus = table.checkStatus('dataTableId');
    checkStatus.data.forEach(element => {
      delUids.push(element.uid);
    });

    if(delUids.length == 0){
      layer.msg('批量删除至少选中一项数据',function(){});
      return false;
    }

    var username = $("#username").val();
    var password = $("#password").val();
    var doSearchDoc = $("#do_search");
    layer.confirm('真的要删除选中的项吗？',function(index){
        layer.close(index);
        index = layer.load(1, {shade: [0.1,'#fff']});

        $.ajax({
          type:'post',
          data:{
            "delUIds": delUids,
            "username": username,
            "password": password,
            "softId":'1198141497808330753',
          },
          url:'http://xiaoc.store/verify/yxmh/del',
          success:function(data){
            if(data.code==10){
              doSearchDoc.click();
            }
            parent.layer.close(index);
            parent.layer.msg(data.msg);
          },error:function(code){   
            parent.layer.msg('操作失败!',{icon: 5,time:1000});  
          }
        });
    })
  }); 

});
</script>
</body>
</html>        
        